<?php
$this->Html->script('controllers/Teams/magic.js?2', array('block' => 'scriptBottom'));
$this->Html->script('controllers/Teams/lines.js?1', array('block' => 'scriptBottom'));
$this->Html->script('controllers/Teams/teams.js?4', array('block' => 'scriptBottom'));
$this->Html->script('controllers/Teams/users.js?5', array('block' => 'scriptBottom'));
$this->Html->script('vendors/kendo/pako_deflate.min', array('block' => 'scriptBottom'));
$this->Html->css('controllers/Teams/teams.css?2', array('block' => 'stylesTop'));
$this->Html->css('controllers/Teams/lines.css?1', array('block' => 'stylesTop'));
$this->Html->css('controllers/Teams/users.css?3', array('block' => 'stylesTop'));
$this->Html->css('controllers/Teams/magic.css?3', array('block' => 'stylesTop'));
$appBosch->urlCreateGroup = $this->Html->url(array('action'=>'create'));
$appBosch->urlReadGroups = $this->Html->url(array('action'=>'read'));
$appBosch->urlDestroyGroup = $this->Html->url(array('action'=>'destroy'));
$appBosch->urlMh = $this->Html->url(array('controller'=>'Abilities','action'=>'admin'));
$appBosch->urlTeam = $this->Html->url(array('action'=>'details'));
$appBosch->urlSaveNameTeam = $this->Html->url(array('action'=>'saveName'));
$appBosch->urlTeamById = $this->Html->url(array('action'=>'get'));
$appBosch->urlTeamLinesCreate = $this->Html->url(array('controller'=>'TeamLines', 'action'=>'create'));
$appBosch->urlTeamLinesRead = $this->Html->url(array('controller'=>'TeamLines', 'action'=>'read'));
$appBosch->urlTeamLinesRead = $this->Html->url(array('controller'=>'TeamLines', 'action'=>'read'));
$appBosch->urlTeamLinesDestroy = $this->Html->url(array('controller'=>'TeamLines', 'action'=>'destroy'));
$appBosch->urlTeamUsersCreate = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'addTeamUser'));
$appBosch->urlTeamUsersRead = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'read'));
$appBosch->urlTeamUsersDestroy = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'destroy'));
$appBosch->urlTeamUsersMultiple = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'addUsers'));
$appBosch->urlDelTeamUsersMultiple = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'deleteUsers'));
$appBosch->urlGetTeamBySeed = $this->Html->url(array('controller'=>'Teams', 'action'=>'getBySeed'));
$appBosch->urlGetUsersTeam = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'getUsersByTeam'));
$appBosch->urlUpdTeam = $this->Html->url(array('controller'=>'Teams', 'action'=>'updTeamConf'));
$appBosch->urlCleanTeam = $this->Html->url(array('controller'=>'Teams', 'action'=>'cleanTeam'));
$appBosch->urlPassport = $this->Html->url(array('controller'=>'Passports', 'action'=>'teamsPassports'));
$appBosch->urlDash = $this->Html->url(array('controller' => 'Dash', 'action' => 'index', 0));
$appBosch->urlActiveTeamUsers = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'getActiveTeamUsers'));
$appBosch->urlToggleUserLeader = $this->Html->url(array('controller'=>'TeamUsers', 'action'=>'toggleUserLeader'));
$appBosch->msgCleanTeam = __('Se eliminarán las líneas y asociados asignados. ¿Deseas continuar?');
$appBosch->qMessages = array(
    'msgAddUsersDetails' => __('No se agregaron algunos asociados:'),
    'txtMessage' => __('Vas a cambiar la línea virtual, ¿Deseas continuar?'),
    'Yes' => __('Si'),
    'No' => __('No'),
    'msgAddedUsers' => 'Se agregaron XX asociados.',
    'msgDeletedUsers' => 'Se eliminaron XX asociados.',
    'msgAddedUsersError'=> ' Los siguientes asociados no se pudieron agregar:',
    'msgDeletedUsersError'=> ' Los siguientes asociados no se pudieron eliminar:',
);
?>
<!--Template de los equipos-->
<script type='text/x-kendo-template' id='templateTeam'>
    <div class='team droptarget' data-area-id="#=area_id#" data-shift="#=shift_id#" data-type="#=type#" title='#=name#'
         data-team-id="#=id#" data-team-name="#=name#" data-team-line="#=real_line#" data-team-line-id="#=line_id#"
         style="border-color: #=colour_virtual_line#">
        <div>
            <i class="fa fa-circle" style="color: #=colour_real_line#"
               title="<?php echo('Línea'); ?>: #=real_line !== null ? real_line : 'Flexible'#"></i>
            <i class="fa fa-square" style="color: #=colour_virtual_line#" title="<?php echo('Turno'); ?>: #=shift#"></i>
            <i class="fa fa-credit-card" style="color: #=colour_virtual_line#"
               title="<?php echo __('Muestra los pasaportes del equipo'); ?>"></i>
            <i class="fa fa-dashboard" style="color: #=colour_virtual_line#"
               title="<?php echo __('Concentrado Dash'); ?>"></i>
            <i class='fa fa-wrench' style="color: #=colour_virtual_line#" data-team-name="#=name#"
               data-shift-id="#=shift_id#" data-team-id="#=id#" title="<?php echo __('Configurar equipo'); ?>"></i>
            <div class="name">#=name#</div>
            #if(type === "1"){#
                <i class='fa fa-times destroy' title="<?php echo __('Eliminar equipo');?>"></i>
            #}#
            #if(nomina === null){#
            <i class="fa fa-group" style="color: #=colour_virtual_line#"></i>
            #}else{#
            <img src="/img/workers-mini/#=nomina#.jpg" alt="#=nomina#" title="#=leader# - #=nomina#">
            #}#
        </div>
    </div>
</script>
<script type='text/x-kendo-template' id='templateToolTipTeam'>
    <div>
        <?php echo __('Equipo');?>: #=target.data('teamName')#
    <br/>
        <?php echo __('Línea');?>: #=target.data('teamLine')#
    <br/>
    </div>
</script>
<!--Template de las lineas disponibles-->
<script type='text/x-kendo-template' id='templateLine'>
    <div class='line draggable' title='#=text#' data-line-id="#=value#" data-line-name="#=text#" data-line-colour="#=colour#" style='background-color: #=colour#'>
    <div>
    #=text#
    </div>
    </div>
</script>
<!--Template de las lineas asignadas-->
<script type='text/x-kendo-template' id='templateTeamLine'>
    <div class='line' title='#=line_name#' data-id="#=id#" data-line-id="#=line_id#" data-line-name="#=line_name#" data-line-colour="#=line_colour#" style='background-color: #=line_colour#'>
    <i class='fa fa-times destroy' title="<?php echo __('Eliminar línea asignada');?>"></i>
    <div>
    #=line_name#
    </div>
    </div>
</script>
<script type='text/x-kendo-template' id='templateGroupDetail'>
    <div>
    <label for="line"><?php echo __('Línea');?></label>
    <input id="line" type='text' value='#=line#' readonly="readonly"/>
    </div>
    <div>
    <label for="shift"><?php echo __('Turno');?></label>
    <input id="shift" type='text' value='#=shift#' readonly="readonly"/>
    </div>
</script>
<!--Template para los usuarios-->
<script type="text/x-kendo-template" id="templateUser">
    <div class='user draggable' title='#=full_name#' data-user-id='#=id#' data-user-name="#=full_name#" data-user-nomina="#=nomina#" data-user-curp="#=curp#" data-user-admission-date="#=admission_date#">
        <table>
            <tr>
                <td rowspan="2">
                    <?php echo $this->Html->image('workers-mini/#=nomina#.jpg'); ?>
                    <div class="nomina">#=nomina#</div>
                </td>
                <td>
                    <div class="fullName">#=full_name#</div>
                    <div class="curp">#=curp#</div>
                </td>
            </tr>
            <tr>
                <td></td>
            </tr>
        </table>
    </div>
</script>
<script type="text/x-kendo-template" id="templateTeamUser">
    <div class='teamUser draggable' data-id="#=id#" data-user-id='#=user_id#' data-user-name="#=full_name#" data-user-nomina="#=nomina#" data-user-curp="#=curp#" data-user-admission-date="#=admission_date#">
        <table>
            <tr>
                <td class="icon">
                    <?php
                        echo $this->Html->image('workers-mini/#=nomina#.jpg', array('class' => 'st-#=status#'));
                    ?>
                    <div class="nomina">#=nomina#</div>
                </td>
                <td class="detail">
                    <div class="fullName">#=full_name#</div>
                    <div class="curp">#=curp#</div>
                </td>
                <td class="destroy">
                    <i class='fa fa-times destroy' title="<?php echo __('Eliminar usuario asignado');?>"></i>
                    # if(leader == "1") { #
                        <i class='fa fa-star leader' title="<?php echo __('Lider');?>"></i>
                    # } else { #
                        <i class='fa fa-star' title=""></i>
                    # } #
                </td>
            </tr>
        </table>
    </div>
</script>
<script type="text/kendo-template" id="dlgWindowTemplate">
    <p>#=txtMessage#</p>
    <div class="optionsDlg">
        <button class="k-button" id="yesButton">#=Yes#</button>
        <button class="k-button" id="noButton">#=No#</button>
    </div>
</script>
<script type="text/kendo-template" id="dlgConfirm">
    <p>#=msgConfirm#</p>
    <div class="optionsDlg">
        <button class="k-button" id="yesButton">#=Yes#</button>
        <button class="k-button" id="noButton">#=No#</button>
    </div>
</script>
<script type="text/kendo-template" id="templateAddErrors">
    <p>#=msg#</p>
    <ul>
        # for (var i = 0; i < userErrors.length; i++) { #
        <li>
            <span class="nomina">#=userErrors[i].nomina#</span>
            <span class="error">
            #if( userErrors[i].ec == '01' ){#
                <?php echo __('No existe usuario para esta línea');?>
            #}else if( userErrors[i].ec == '02' ){#
                <?php echo __('El usuario no tiene certificaciones');?>
            #}else if( userErrors[i].ec == '03' ){#
                <?php echo __('El usuario ya existe en el equipo');?>
            #}else if( userErrors[i].ec == '04' ){#
                <?php echo __('El usuario no existe en el equipo');?>
            #}#
            </span>
        </li>
        # } #
    </ul>
</script>
<script type="text/kendo-template" id="templateAsocLength">
    #if( count !== 0 ){#
    <span class="lengthUsers">#=count#</span>
    #}#
    #if( count === 0 ){#
        <?php echo __('Sin asociados');?>
    #}else if( count > 1 ){#
        <?php echo __(' asociados');?>
    #}else{#
        <?php echo __(' asociado');?>
    #}#
    #if( leaders !== 0 ){#
        (
        <span class="lengthUsers">#=leaders#</span>
    #}#
    #if( leaders === 1 ){#
        <?php echo __(' lider');?>
    #}else if( leaders > 1 ){#
        <?php echo __(' lideres');?>
    #}else{#
        <?php echo __('');?>
    #}#
    #if( leaders !== 0 ){#
        )
    #}#
</script>

<!--Equipos-->
<div>
    <div class="pull-left">
        <button class='btn btn-primary' id='addTeam' type='button'>
            <i class='fa fa-plus'></i>
            <?php echo __('Agregar equipo');?>
        </button>
        <button class='btn btn-primary' id='exportPDF' type='button'>
            <i class='fa fa-pdf'></i>
            <?php echo __('Exportar a PDF');?>
        </button>
    </div>
    <div class="pull-right">
        <div class="form-inline" role="form" id="formGetTeamByUser">
            <div class="form-group">
                <div class="input-group">
                    <label class="sr-only" for="getTeamByUser"><?php echo __('Buscar asociado');?></label>
                    <input type="text" class="form-control" id="getTeamByUser" placeholder="Buscar por: usuario | equipo | línea | nomina | curp">
                    &nbsp;
                    <button class='btn btn-primary' type="button">
                        <?php echo __('Buscar');?>
                    </button>
                    <i class="fa fa-refresh fa-spin hidden"></i>
                </div>
            </div>
        </div>
    </div>
</div>
<br/>
<br/>
<!--Equipos filtrados-->
<div class='container-teams'>
        <!--Aqui se insertan todos los equipos del area-->
</div>

<div class='container-teams-filter hidden'>
    <div class='results hidden'>
        <div class='teams'>
            <!--Aqui se insertan los equipos filtrados-->
        </div>
    </div>
    <div class='noResults hidden alert alert-info'>
        <?php echo __('No se encontraron equipos que coincidan con el criterio de búsqueda');?>
    </div>
    <div>
        <button class='btn btn-primary'>
        <?php echo __('Ver todos los equipos');?>
        </button>
    </div>
</div>
<!--Fin equipos filtrados-->
<!--Ventana de la edicion del grupo-->
<div class="hide">
    <div id='wndTeam'>
        <div class="col-lg-12">
            <label for="#nameTeam"><?php echo ('Nombre del equipo');?></label>
            <input id="nameTeam" type="text" value=""/>
            <button class='btn btn-danger pull-right' id='cleanTeam' type='button' title="<?php echo __('Elimina líneas y asociados del equipo');?>">
                <i class='fa fa-trash-o'></i>
                <?php echo __('Limpiar equipo');?>
            </button>
        </div>
        <div class="col-lg-12 virtualLines">
            <label for="virtualLines" ><?php echo __('Línea Virtual'); ?>:</label>
            <input id="virtualLines" name="virtualLines" style="width: 860px;" required/>
        </div>
        <div class="col-lg-12 shifts">
            <label for="shifts"><?php echo __('Turno'); ?>:</label>
            <input id="shifts" name="shifts" style="width: 430px;" required/>
        </div>
        <div class="lineAndShift"></div>
        <div class="container-users">
            <div class="col-lg-5 pull-left">
                <h3><?php echo __('Asociados asignados');?></h3>
                <div class="form-inline" role="form">
                    <div class="form-group">
                        <label for="addByNomina" class="sr-only"><?php echo __('Número de nómina');?></label>
                        <input type="text" class="form-control" id="addByNomina" placeholder="<?php echo __('Número de nómina');?>">
                    </div>
                    <button type="button" class="btn btn-default pull-right" id="addUsers">
                        <i class="fa fa-plus"></i>
                        <?php echo __('Agregar');?>
                    </button>
                </div>
            </div>
            <div class="col-lg-5 pull-left">
                <h3>&nbsp;</h3>
                <div class="form-inline" role="form">
                    <div class="form-group">
                        <label for="deleteByNomina" class="sr-only"><?php echo __('Número de nómina');?></label>
                        <input type="text" class="form-control" id="deleteByNomina" placeholder="<?php echo __('Número de nómina');?>">
                    </div>
                    <button type="button" class="btn btn-default pull-right" id="deleteUsers">
                        <i class="fa fa-minus"></i>
                        <?php echo __('Eliminar');?>
                    </button>
                </div>
            </div>
            <div class="my col-lg-11 center-block"></div>
            <span id="asocLength" class="pull-right"></span>
        </div>
        <div class="container-lines">
            <div class="col-lg-5 pull-left">
                <h3><?php echo __('Líneas asignadas');?></h3>
                <div class="my" id="droptargetLine">
                </div>
            </div>
            <div class="col-lg-6 pull-right">
                <h3><?php echo __('Líneas disponibles');?></h3>
                <div class="all">
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dlg"></div>

<div id="dlgU"></div>

<div id="loading" class='k-loading-mask'>
    <span class='k-loading-text'><?php echo __('Agregando');?>...</span>
    <div class='k-loading-image'/>
    <div class='k-loading-color'/>
</div>
<?php $this->start('jsVars'); ?>
<script type="text/javascript">
    var appBosch = <?php echo json_encode($appBosch); ?>;
</script>
<?php
$this->end();
